import React, { useRef } from 'react'
import  Child4 from "../components/Child4";

export default function UseRef() {

    let usernameInput:any = useRef(null);
    let child4:any= useRef(null);

    return (
        <div>UseRef
            <input type="text" ref={usernameInput} />
            <button onClick={() => {
                console.log(usernameInput.current.value)
            }}>取值</button>

            <button onClick={()=>{
                console.log(child4.current.getUserage());  
            }}>获取子组件的数据</button>


            <Child4 ref={child4}></Child4>
        </div>
    )
}




// import React, { Component } from 'react'
// export default class UseRef extends Component {
//   render() {
//     return (
//       <div>
//           <input type="text" ref="username" />
//           <button onClick={()=>{
//               alert((this.refs.username as HTMLInputElement).value)
//           }}>取值</button>

//       </div>
//     )
//   }
// }

